import 'dart:collection';
import 'dart:math';

import 'package:common_utils/common_utils.dart';

import '../native/native.dart';
import 'dart:io';
import 'bison.dart';
import 'core.dart';
import 'interpreter.dart';
import 'utils.dart';
/**
 *   PACKAGE:
 *   USER:Administrator
 *   TIME:2021/1/3 0003 17:02
 *   Description:
 */

///传进来的文件作为主脚本文件
void interpreter_compile(String filePath) {
  yyFile = File(filePath);
  Interpreter.getInstance().proDir = yyFile.parent.path; //设置项目基本属性时使用filepath

  List<String> package = List();
  String temp;
  temp = filePath.split('\\').last.toLowerCase();
  temp = temp.replaceRange(temp.length - 3, temp.length, '');
  Interpreter.getInstance().mainModule = temp;

  ///暂存未编译的依赖包
  int i = 0;
  while (true) {
    if (!yyFile.existsSync()) {
      print("file not find:${yyFile.path}");
      break;
    }
    code = yyFile.readAsBytesSync();
    code_len = code.length;

    ///[todo] 是否限制文件大小
    print("code_len:$code_len");
    // temp = yyFile.path.split('\\').last.toLowerCase();
    // temp = temp.replaceRange(temp.length - 3, temp.length, '');
    Module module = Module(temp.split('.').last, yyFile.path);

    ///新建一个模块，命名以文件路径命,其内容将有编译器添加
    if (yyParse(module)) {
      ///分析完一个文件之后添加模块到编译器
      ///在此分析各个文件的依赖关系

      Interpreter.getInstance().module.putIfAbsent(temp, () => module);

      ///添加当前模块的依赖包，重复的不增加.
      module.imp.forEach((key, value) {
        print("import:" + key + " " + value);

        ///cool包不需要读取文件
        if (value.startsWith('cool.')) {
          if (!Interpreter.getInstance().module.containsKey(value)) {
            ///内置函数包
            Module mod = add_native_functions(value);
            if (mod != null)
              Interpreter.getInstance().module.putIfAbsent(value, () => mod);
          }
          return;
        }
        if (!package.contains(value)) {
          package.add(value);
        }
      });
      if (i == package.length) {
        print("yyParse ok");
        print("module:${Interpreter.getInstance().module.toString()}");
        print(Interpreter.getInstance()
            .module[Interpreter.getInstance().mainModule]);
        return;
      }

      print("module:${Interpreter.getInstance().module.toString()}");

      ///开始分析依赖包
      if (package[i].startsWith('pub.')) {
        ///公共函数包
        // print(package[i]);
      } else {
        ///工程依赖包,替换路径
        print("添加工程依赖:${package[i]}");
        String t1 = Interpreter.getInstance().proDir +
            ('\\' + package[i].replaceAll('.', '\\') + '.yz');
        print(t1);
        yyFile = File(t1);
        temp = package[i];
      }
      i++;
    } else {
      print("yyParse error");
      // if (rules.isEmpty) {
      //   print("==> Status${status} ${rules}");
      //   return;
      // }
      // print(
      //     "${rules.first.line_number}:${rules.last.line_number}==> Status${status} ${rules}");

      break;
    }
  }
}

///增加内置本地函数和本地变量
void add_native_variables() {}

Module add_native_functions(String value) {
  String temp = value.split('.').last.toLowerCase();

  Module module = Module(temp, value);
  print("添加Cool包:$temp");
  switch (temp) {
    case 'core':
      add_core_functions(module);
      break;
    default:
      print("本地包不存在,不应该产生的错误");
      return null;
  }

  return module;
}

///解释语句
StatementResult interpreter_run(LinkedList<Variable> localEnvironment,
    String module, LinkedList<Statement> list) {
  StatementResult result = StatementResult();

  if (!Interpreter.getInstance().module.containsKey(module)) {
    print("$module不存在");
    result.type = StatementResultType.ERROR_RUNTIME_RESULT;
    result.error = "$module不存在";
    return result;
  }
  print("开始语句运行module:$module");
  if (!Interpreter.getInstance().module[module].getLoad) {
    ///进行其它模块全局变量注册
    Interpreter.getInstance().module[module].setLoad = true;
    FunctionDefinition functionDefinition = search_function(module, "load");
    if ((functionDefinition != null) &&
        (functionDefinition.parameter.isEmpty)) {
      result = interpreter_run(
          Interpreter.getInstance().module[module].variable,
          module,
          functionDefinition.block.statement_list);
      if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
        Interpreter.getInstance().module[module].setLoad = false;
        return result;
      }
    }
  }
  for (var s = list?.first; s != null; s = s.next) {
    result = execute_statement(localEnvironment, module, s);
    if (result.type != StatementResultType.NORMAL_STATEMENT_RESULT) break;
  }
  return result;
}

StatementResult execute_statement(
    LinkedList<Variable> localEnvironment, String module, Statement statement) {
  StatementResult result = StatementResult();
  switch (statement.type) {
    case StatementType.EXPRESSION_STATEMENT:
      result = expression_statement(
          localEnvironment, module, statement.expression_s);
      break;
    case StatementType.CONST_STATEMENT:
      result = const_statement(localEnvironment, module, statement.const_s);
      break;
    case StatementType.BLOCK_STATEMENT:
      result =
          block_statement(localEnvironment, module, statement.block_s.block);
      break;
    case StatementType.IF_STATEMENT:
      result = if_statement(localEnvironment, module, statement.if_s);
      break;
    case StatementType.WHILE_STATEMENT:
      result = while_statement(localEnvironment, module, statement.while_s);
      break;
    case StatementType.FOR_STATEMENT:
      result = for_statement(localEnvironment, module, statement.for_s);
      break;
    case StatementType.RETURN_STATEMENT:
      result = return_statement(localEnvironment, module, statement.return_s);
      break;
    case StatementType.BREAK_STATEMENT:
      result.type = StatementResultType.BREAK_STATEMENT_RESULT;
      break;
    case StatementType.CONTINUE_STATEMENT:
      result.type = StatementResultType.CONTINUE_STATEMENT_RESULT;
      break;
    case StatementType.SWITCH_STATEMENT:
      result = switch_statement(localEnvironment, module, statement.switch_s);
      break;
    case StatementType.TRY_STATEMENT:
      result = try_statement(localEnvironment, module, statement.try_s);
      break;
    case StatementType.STATEMENT_TYPE_COUNT_PLUS_1:
      result.type = StatementResultType.STATEMENT_RESULT_TYPE_COUNT_PLUS_1;
      result.error = "语句类型错误";
      break;
  }
  return result;
}

StatementResult switch_statement(LinkedList<Variable> localEnvironment,
    String module, SwitchStatement switch_s) {
  StatementResult result =
      expression_statement(localEnvironment, module, switch_s.expression);
  if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
    StatementResult result1;
    for (var t1 = switch_s.case_list.first; t1 != null; t1 = t1.next) {
      for (var t2 = t1.expression_list.first; t2 != null; t2 = t2.next) {
        result1 = expression_statement(localEnvironment, module, t2);
        if (result1.return_value == result.return_value) {
          result = interpreter_run(
              localEnvironment, module, t1.block.statement_list);
          return result;
        }
      }
    }
    if (switch_s.default_block != null)
      result = interpreter_run(
          localEnvironment, module, switch_s.default_block.statement_list);
  }
  return result;
}

StatementResult try_statement(
    LinkedList<Variable> localEnvironment, String module, TryStatement try_s) {
  StatementResult result = StatementResult();

  result =
      interpreter_run(localEnvironment, module, try_s.try_block.statement_list);
  if (result.type == StatementResultType.BREAK_STATEMENT_RESULT) {
    result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
  } else if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
    result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
    var t1 = Variable(
        try_s.exception, Value(ValueType.STRING_VALUE, result.error), true);
    if (localEnvironment == null) {
      Interpreter.getInstance().module[module].variable.add(t1);
    } else {
      localEnvironment.add(t1);
    }
    result = interpreter_run(
        localEnvironment, module, try_s.catch_block.statement_list);
    if (localEnvironment == null) {
      Interpreter.getInstance().module[module].variable.remove(t1);
    } else {
      localEnvironment.remove(t1);
    }
  }

  if ((result.type == StatementResultType.NORMAL_STATEMENT_RESULT) &&
      (try_s.finally_block != null)) {
    result = interpreter_run(
        localEnvironment, module, try_s.finally_block.statement_list);
  }
  return result;
}

StatementResult while_statement(LinkedList<Variable> localEnvironment,
    String module, WhileStatement while_s) {
  StatementResult result = StatementResult();

  for (;;) {
    result = expression_statement(localEnvironment, module, while_s.condition);
    if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
      return result;
    }
    if (result.return_value.type != ValueType.BOOLEAN_VALUE) {
      result.type = StatementResultType.ERROR_RUNTIME_RESULT;
      result.error = "${result.return_value.type}不是bool型2";
      return result;
    }
    if (!result.return_value.value) {
      break;
    }
    result =
        interpreter_run(localEnvironment, module, while_s.block.statement_list);
    if (result.type == StatementResultType.RETURN_STATEMENT_RESULT) {
      break;
    } else if (result.type == StatementResultType.BREAK_STATEMENT_RESULT) {
      result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
      break;
    }
  }
  return result;
}

StatementResult return_statement(LinkedList<Variable> localEnvironment,
    String module, ReturnStatement return_s) {
  StatementResult result = StatementResult();
  if (return_s.return_value != null) {
    result =
        expression_statement(localEnvironment, module, return_s.return_value);
  } else {
    result.return_value.type = ValueType.NULL_VALUE;
    result.return_value.value = null;
  }
  if (result.type != StatementResultType.ERROR_RUNTIME_RESULT)
    result.type = StatementResultType.RETURN_STATEMENT_RESULT;
  return result;
}

StatementResult for_statement(
    LinkedList<Variable> localEnvironment, String module, ForStatement for_s) {
  StatementResult result = StatementResult();
  if (for_s?.init?.type != null) {
    result = expression_statement(localEnvironment, module, for_s.init);
  }
  if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
    for (;;) {
      if (for_s?.condition?.type != null) {
        result =
            expression_statement(localEnvironment, module, for_s.condition);
        if ((result.return_value.type != ValueType.BOOLEAN_VALUE)) {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "${result.return_value.type}不是bool型2";
          return result;
        } else if (!result.return_value.value) {
          break;
        }
      }
      result =
          interpreter_run(localEnvironment, module, for_s.block.statement_list);

      if (result.type == StatementResultType.RETURN_STATEMENT_RESULT) {
        break;
      } else if (result.type == StatementResultType.BREAK_STATEMENT_RESULT) {
        result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
        break;
      }
      if (for_s?.post?.type != null) {
        result = expression_statement(localEnvironment, module, for_s.post);
      }
    }
  }

  return result;
}

StatementResult if_statement(
    LinkedList<Variable> localEnvironment, String module, IfStatement if_s) {
  StatementResult result = StatementResult();
  result = expression_statement(localEnvironment, module, if_s.condition);

  if (result.return_value.type == ValueType.BOOLEAN_VALUE) {
    if (result.return_value.value) {
      result = interpreter_run(
          localEnvironment, module, if_s.then_block.statement_list);
      //result = block_statement(localEnvironment, module, if_s.then_block);
    } else {
      for (var t1 = if_s.elsif_list?.first; t1 != null; t1 = t1.next) {
        result = expression_statement(localEnvironment, module, t1.condition);
        if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
          return result;
        }
        if (result.return_value.type != ValueType.BOOLEAN_VALUE) {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "${result.return_value.type}不是bool型1";
          return result;
        }
        if (result.return_value.value) {
          if (interpreter_run(localEnvironment, module, t1.block.statement_list)
                  .type ==
              StatementResultType.ERROR_RUNTIME_RESULT) {
            return result;
          }
          break;
        }
      }
      if (!result.return_value.value && (if_s.else_block != null)) {
        result = interpreter_run(
            localEnvironment, module, if_s.else_block.statement_list);
      }
    }
  } else {
    result.type = StatementResultType.ERROR_RUNTIME_RESULT;
    result.error = "${result.return_value.type}不是bool型";
  }
  return result;
}

StatementResult block_statement(
    LinkedList<Variable> localEnvironment, String module, Block block_s) {
  StatementResult result = StatementResult();
  LinkedList<Variable> _localEnvironment = LinkedList();
  if (localEnvironment == null) {
    localEnvironment = LinkedList();
  } else {
    localEnvironment.forEach((entry) {
      _localEnvironment.add(Variable(entry.name, entry.value, entry.isFixed));
    });
  }
  result = interpreter_run(_localEnvironment, module, block_s.statement_list);

  localEnvironment.forEach((entry) {
    if (entry.isFixed) return;
    _localEnvironment.forEach((e) {
      if (entry.name == e.name) {
        entry.value = e.value;
      }
    });
  });

  if ((result.type == StatementResultType.CONTINUE_STATEMENT_RESULT) ||
      (result.type == StatementResultType.BREAK_STATEMENT_RESULT))
    result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
  return result;
}

StatementResult const_statement(LinkedList<Variable> localEnvironment,
    String module, ConstStatement const_s) {
  StatementResult result;
  for (var t1 = const_s.identifier_list.first; t1 != null; t1 = t1.next) {
    result = expression_statement(
        localEnvironment, module, t1.expression.assign_expression.operand);
    if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
      return result;
    }
    for (var t2 = Interpreter.getInstance().module[module].function_list.isEmpty
            ? null
            : Interpreter.getInstance().module[module].function_list.first;
        t2 != null;
        t2 = t2.next) {
      if (t2.name == t1.expression.assign_expression.left.identifier) {
        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
        result.error = "同名定义${t2.name}";
        return result;
      }
    }
    bool exit = false;
    if (localEnvironment == null) {
      Interpreter.getInstance().module[module].variable.forEach((entry) {
        if (entry.name == t1.expression.assign_expression.left.identifier) {
          exit = true;
        }
      });
      if (!exit)
        Interpreter.getInstance().module[module].variable.add(Variable(
            t1.expression.assign_expression.left.identifier,
            result.return_value,
            true));
    } else {
      localEnvironment
        ..forEach((entry) {
          if (entry.name == t1.expression.assign_expression.left.identifier) {
            exit = true;
          }
        });
      if (!exit)
        localEnvironment.add(Variable(
            t1.expression.assign_expression.left.identifier,
            result.return_value,
            true));
    }
    if (exit) {
      result.type = StatementResultType.ERROR_RUNTIME_RESULT;
      result.error = "同名定义${t1.expression.assign_expression.left.identifier}";
    }
  }
  return result;
}

StatementResult expression_statement(LinkedList<Variable> localEnvironment,
    String module, Expression expression_s) {
  StatementResult result = StatementResult();
  Value v;
  switch (expression_s.type) {
    case ExpressionType.BOOLEAN_EXPRESSION:
      v = Value(ValueType.BOOLEAN_VALUE, expression_s.bool_value);
      result.return_value = v;
      break;
    case ExpressionType.INT_EXPRESSION:
      v = Value(ValueType.INT_VALUE, expression_s.int_value);
      result.return_value = v;
      break;
    case ExpressionType.DOUBLE_EXPRESSION:
      v = Value(ValueType.DOUBLE_VALUE, expression_s.double_value);
      result.return_value = v;
      break;
    case ExpressionType.STRING_EXPRESSION:
      v = Value(ValueType.STRING_VALUE, expression_s.string_value);
      result.return_value = v;
      break;
    case ExpressionType.REGEXP_EXPRESSION:
      v = Value(ValueType.REGEXP_VALUE, expression_s.string_value);
      result.return_value = v;
      break;
    case ExpressionType.IDENTIFIER_EXPRESSION:
      if (localEnvironment != null) {
        ///表示有本地变量环境,因为本地变量访问全局变量都需要使用$符号
        v = search_local_variable(localEnvironment, expression_s.identifier);
      } else {
        v = search_global_variable(module, expression_s.identifier);
      }
      if (v == null) {
        String t1 = search_function(module, expression_s.identifier)?.name;
        if (t1 != null) {
          v = Value(ValueType.FUNCTION_VALUE, t1);
        } else {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "${expression_s.identifier}未定义";
        }
      }
      result.return_value = v;
      break;
    case ExpressionType.GLOBAL_EXPRESSION:
      v = search_global_variable(module, expression_s.identifier);
      if (v == null) {
        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
        result.error = "${expression_s.identifier}未定义";
      }

      result.return_value = v;
      break;
    case ExpressionType.COMPLEX_EXPRESSION:

      ///排除0i的情况
      if ((expression_s.int_value ?? expression_s.double_value) == 0) {
        v = Value(ValueType.INT_VALUE, 0);
      } else
        v = Value(ValueType.COMPLEX_VALUE,
            Complex(0, expression_s.int_value ?? expression_s.double_value));
      result.return_value = v;
      break;
    case ExpressionType.COMMA_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.comma.left);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        result = expression_statement(
            localEnvironment, module, expression_s.comma.right);
      }
      break;
    case ExpressionType.ASSIGN_EXPRESSION:

      ///=为增加变量，其余为变量操作
      result = expression_statement(
          localEnvironment, module, expression_s.assign_expression.operand);

      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        ///如果是模块调用表达式,不允许给另一个模块增改变量
        // print("###${expression_s.assign_expression.left.module}");
        // if(expression_s.assign_expression.left.module!=null){
        //   module = Interpreter.getInstance().module[module].imp[expression_s.assign_expression.left.module];
        // }
        if ((expression_s.assign_expression.left.type ==
                ExpressionType.IDENTIFIER_EXPRESSION) ||
            (expression_s.assign_expression.left.type ==
                ExpressionType.GLOBAL_EXPRESSION) ||
            (expression_s.assign_expression.left.type ==
                ExpressionType.INDEX_EXPRESSION)) {
          ///搜索是否有同名函数定义,只搜索本模块内部
          for (var t1 =
                  Interpreter.getInstance().module[module].function_list.isEmpty
                      ? null
                      : Interpreter.getInstance()
                          .module[module]
                          .function_list
                          .first;
              t1 != null;
              t1 = t1.next) {
            if (t1.name == expression_s.assign_expression.left.identifier) {
              result.type = StatementResultType.ERROR_RUNTIME_RESULT;
              result.error =
                  "同名定义${expression_s.assign_expression.left.identifier}";
              return result;
            }
          }
          if (expression_s.assign_expression.operator !=
              AssignmentOperator.NORMAL_ASSIGN) {
            expression_s.binary_expression.left =
                expression_s.assign_expression.left;
            expression_s.binary_expression.right =
                expression_s.assign_expression.operand;
            switch (expression_s.assign_expression.operator) {
              case AssignmentOperator.ADD_ASSIGN:
                expression_s.type = ExpressionType.ADD_EXPRESSION;
                break;
              case AssignmentOperator.SUB_ASSIGN:
                expression_s.type = ExpressionType.SUB_EXPRESSION;
                break;
              case AssignmentOperator.MUL_ASSIGN:
                expression_s.type = ExpressionType.MUL_EXPRESSION;
                break;
              case AssignmentOperator.DIV_ASSIGN:
                expression_s.type = ExpressionType.DIV_EXPRESSION;
                break;
              case AssignmentOperator.MOD_ASSIGN:
                expression_s.type = ExpressionType.MOD_EXPRESSION;
                break;
              case AssignmentOperator.BIT_XOR_ASSIGN:
                expression_s.type = ExpressionType.BIT_XOR_EXPRESSION;
                break;
              case AssignmentOperator.BIT_AND_ASSIGN:
                expression_s.type = ExpressionType.BIT_AND_EXPRESSION;
                break;
              case AssignmentOperator.BIT_OR_ASSIGN:
                expression_s.type = ExpressionType.BIT_OR_EXPRESSION;
                break;
              case AssignmentOperator.NORMAL_ASSIGN:
                expression_s.type = ExpressionType.ASSIGN_EXPRESSION;
                break;
            }
            result =
                expression_statement(localEnvironment, module, expression_s);
          }

          if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
            ///只允许修改，不许增加
            if (expression_s.assign_expression.left.type ==
                ExpressionType.INDEX_EXPRESSION) {
              result = expression_statement(localEnvironment, module,
                  expression_s.assign_expression.left.index_expression.array);
              if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
                if (result.return_value.type == ValueType.ARRAY_VALUE) {
                  Array t1 = result.return_value.value;
                  result = expression_statement(
                      localEnvironment,
                      module,
                      expression_s
                          .assign_expression.left.index_expression.index);
                  if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
                    if (result.return_value.type == ValueType.INT_VALUE) {
                      int t2 = 0;
                      for (var t5 = 0; t5 < t1.array[t5].length; t5++)
                        t4:
                        for (var t3 = t1.array[t5].first;
                            t3 != null;
                            t3 = t3.next) {
                          if (t2 == result.return_value.value) {
                            //t1.array[t5]. = ;
                            t3.insertBefore(
                                expression_s.assign_expression.operand);
                            t1.array[t5].remove(t3);
                            search_and_add_variable(
                                localEnvironment,
                                module,
                                expression_s.assign_expression.left,
                                Value(ValueType.ARRAY_VALUE, t1),
                                false);
                            t2++;
                            break t4;
                          }
                          t2++;
                        }

                      if (t2 <= result.return_value.value) {
                        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                        result.error = "数组下标越界${result.return_value.value}";
                      }
                    } else {
                      result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                      result.error = "数组必须用整数标";
                    }
                  }
                } else {
                  result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                  result.error =
                      "${expression_s.assign_expression.left.index_expression.array.identifier}不是数组类型";
                }
              } else {
                result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                result.error =
                    "未找到:${expression_s.assign_expression.left.index_expression.array.identifier}";
              }
            } else if (expression_s.assign_expression.left.type ==
                ExpressionType.GLOBAL_EXPRESSION) {
              Variable t1;
              Interpreter.getInstance().module[module]?.variable?.forEach((e) {
                if (e.name == expression_s.assign_expression.left.identifier) {
                  t1 = e;
                  if (!e.isFixed) {
                    e.value = result.return_value;
                  } else {
                    print("不可修改常量");
                  }
                }
              });
              if (t1 == null) {
                result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                result.error =
                    "${expression_s.assign_expression.left.identifier}不存在";
              }
              // Interpreter.getInstance().module[module]?.variable?.forEach((v) {
              //   if (v.name == identifier) {
              //     ve = v.value;
              //   }
              // });
            } else
              search_and_add_variable(
                  localEnvironment,
                  module,
                  expression_s.assign_expression.left,
                  result.return_value,
                  false);
          }
        } else {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "左边只能是标志:${expression_s.assign_expression.left.type}";
        }
      }

      break;
    case ExpressionType.ADD_EXPRESSION:
    case ExpressionType.SUB_EXPRESSION:
    case ExpressionType.MUL_EXPRESSION:
    case ExpressionType.DIV_EXPRESSION:
    case ExpressionType.MOD_EXPRESSION:
    case ExpressionType.DOT_DIV_EXPRESSION:
    case ExpressionType.DOT_MUL_EXPRESSION:
    case ExpressionType.BIT_AND_EXPRESSION:
    case ExpressionType.BIT_OR_EXPRESSION:
    case ExpressionType.BIT_XOR_EXPRESSION:
    case ExpressionType.EQ_EXPRESSION:
    case ExpressionType.NE_EXPRESSION:
    case ExpressionType.GT_EXPRESSION:
    case ExpressionType.GE_EXPRESSION:
    case ExpressionType.LT_EXPRESSION:
    case ExpressionType.LE_EXPRESSION:
      result = eval_binary_expression(
        localEnvironment,
        module,
        expression_s,
      );
      break;
    case ExpressionType.LOGICAL_AND_EXPRESSION:
    case ExpressionType.LOGICAL_OR_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.binary_expression.left);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        if (result.return_value.type == ValueType.BOOLEAN_VALUE) {
          if (expression_s.type == ExpressionType.LOGICAL_OR_EXPRESSION) {
            if (!result.return_value.value) {
              result = expression_statement(localEnvironment, module,
                  expression_s.binary_expression.right);
              if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
                if (result.return_value.type == ValueType.BOOLEAN_VALUE) {
                  return result;
                } else {
                  result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                  result.error = "非bool表达式";
                }
              } else
                return result;
            }
          } else {
            if (result.return_value.value) {
              result = expression_statement(localEnvironment, module,
                  expression_s.binary_expression.right);
              if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
                if (result.return_value.type == ValueType.BOOLEAN_VALUE) {
                  return result;
                } else {
                  result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                  result.error = "非bool表达式";
                }
              } else
                return result;
            }
          }
        } else {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "非bool表达式";
        }
      }
      break;
    case ExpressionType.MINUS_EXPRESSION:
      expression_s.type = ExpressionType.SUB_EXPRESSION;
      expression_s.binary_expression.left = Expression()
        ..type = ExpressionType.INT_EXPRESSION
        ..int_value = 0;
      expression_s.binary_expression.right = expression_s.minus_expression;
      result = expression_statement(localEnvironment, module, expression_s);
      break;
    case ExpressionType.BIT_NOT_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.minus_expression);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        if (result.return_value.type == ValueType.INT_VALUE) {
          result.return_value.value = ~result.return_value.value;
        } else {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "非整数表达式";
        }
      }
      break;
    case ExpressionType.LOGICAL_NOT_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.minus_expression);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        if (result.return_value.type == ValueType.BOOLEAN_VALUE) {
          result.return_value.value = !result.return_value.value;
        } else {
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "非bool表达式";
        }
      }
      break;
    case ExpressionType.FUNCTION_CALL_EXPRESSION:
      if ((expression_s.function_call_expression.function.module != null) &&
          (expression_s.function_call_expression.function.module != module)) {
        module = Interpreter.getInstance()
            .module[module]
            .imp[expression_s.function_call_expression.function.module];
      }
      result = function_call_expression(localEnvironment, module, expression_s);

      ///没有return语句时默认添加null值
      break;
    case ExpressionType.NULL_EXPRESSION:
      v = Value(ValueType.NULL_VALUE, null);
      result.return_value = v;
      break;
    case ExpressionType.ARRAY_EXPRESSION:
      if (expression_s.array.array.isNotEmpty) {
        ArrayValue arrayValue = ArrayValue();
        int l = 0;
        t3:
        for (var t1 = 0; t1 < expression_s.array.array.length; t1++) {
          LinkedList<Value> value = LinkedList();

          for (var t2 = expression_s.array.array[t1].first;
              t2 != null;
              t2 = t2.next) {
            result = expression_statement(localEnvironment, module, t2);
            if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
              value.add(
                  Value(result.return_value.type, result.return_value.value));
            } else {
              break t3;
            }
          }
          arrayValue.array.add(value);
          arrayValue.lie.add(expression_s.array.array[t1].length);
          l += expression_s.array.array[t1].length;
        }
        arrayValue.hang = expression_s.array.array.length;
        arrayValue.length = l;
        v = Value(ValueType.ARRAY_VALUE, arrayValue);
      } else {
        v = Value(ValueType.ARRAY_VALUE, ArrayValue());
      }
      result.return_value = v;
      break;
    case ExpressionType.INDEX_EXPRESSION:

      ///不允许访问其他模块的全局变量，数组等[todo]暂时规定用整数标
      if ((expression_s.module == null) || (expression_s.module == module)) {
        result = expression_statement(
            localEnvironment, module, expression_s.index_expression.array);
        if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
          if (result.return_value.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = result.return_value.value;
            result = expression_statement(
                localEnvironment, module, expression_s.index_expression.index);

            ///[todo]，使用逗号表达式快速定位
            if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
              if (result.return_value.type == ValueType.INT_VALUE) {
                if (result.return_value.value < t1.length) {
                  int t2 = 0;
                  t3:
                  for (var i = 0; i < t1.hang; i++) {
                    for (var j = 0; j < t1.lie[i]; j++) {
                      if (t2 == result.return_value.value) {
                        result.return_value = Value(
                            t1.array[i].elementAt(j).type,
                            t1.array[i].elementAt(j).value);
                        break t3;
                      }
                      t2++;
                    }
                  }
                } else {
                  result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                  result.error = "数组下标越界${result.return_value.value}";
                }
              } else {
                result.type = StatementResultType.ERROR_RUNTIME_RESULT;
                result.error = "数组必须用整数标";
              }
            }
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "该变量非数组类型";
          }
        }
      } else {
        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
        result.error = "不允许访问其他模块的全局变量，数组";
      }
      break;
    case ExpressionType.INCREMENT_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.inc_dec.operand);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        expression_s.type = ExpressionType.ASSIGN_EXPRESSION;
        expression_s.assign_expression.operator =
            AssignmentOperator.NORMAL_ASSIGN;
        expression_s.assign_expression.left = expression_s.inc_dec.operand;
        expression_s.assign_expression.operand = Expression()
          ..type = ExpressionType.ADD_EXPRESSION
          ..binary_expression = (BinaryExpression()
            ..left = expression_s.inc_dec.operand
            ..right = (Expression()
              ..type = ExpressionType.INT_EXPRESSION
              ..int_value = 1));
        expression_statement(localEnvironment, module, expression_s);
      }
      break;
    case ExpressionType.DECREMENT_EXPRESSION:
      result = expression_statement(
          localEnvironment, module, expression_s.inc_dec.operand);
      if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
        expression_s.type = ExpressionType.ASSIGN_EXPRESSION;
        expression_s.assign_expression.operator =
            AssignmentOperator.NORMAL_ASSIGN;
        expression_s.assign_expression.left = expression_s.inc_dec.operand;
        expression_s.assign_expression.operand = Expression()
          ..type = ExpressionType.SUB_EXPRESSION
          ..binary_expression = (BinaryExpression()
            ..left = expression_s.inc_dec.operand
            ..right = (Expression()
              ..type = ExpressionType.INT_EXPRESSION
              ..int_value = 1));
        expression_statement(localEnvironment, module, expression_s);
      }
      break;
    case ExpressionType.MODULE_CALL_EXPRESSION:
      expression_s.type = ExpressionType.IDENTIFIER_EXPRESSION;
      result = expression_statement(
          localEnvironment,
          Interpreter.getInstance().module[module].imp[expression_s.module],
          expression_s);
      if (result.type != StatementResultType.ERROR_RUNTIME_RESULT)
        result.return_value.module =
            Interpreter.getInstance().module[module].imp[expression_s.module];
      break;
    case ExpressionType.EXPRESSION_TYPE_COUNT_PLUS_1:
      result.type = StatementResultType.STATEMENT_RESULT_TYPE_COUNT_PLUS_1;
      result.error = "表达式类型错误";
      break;
  }
  return result;
}

StatementResult function_call_expression(LinkedList<Variable> localEnvironment,
    String module, Expression expression_s) {
  StatementResult result = StatementResult();

  ///根据模块名找路径
  if (expression_s.module != null) {
    module = Interpreter.getInstance().module[module].imp[expression_s.module];
  }
  if (module == null) {
    result.type = StatementResultType.ERROR_RUNTIME_RESULT;
    result.error = "module:${expression_s.module}未导入";

    return result;
  }

  ///1.保存标识符
  ///2.搜索本地环境
  ///3.搜索全局环境，有bug 就是无法识别带$的变量 已解决
  String fun_name = expression_s.function_call_expression.function.identifier;
  //print(expression_s.function_call_expression.function.type);
  if ((localEnvironment == null) ||
      (expression_s.function_call_expression.function.type ==
          ExpressionType.GLOBAL_EXPRESSION)) {
    Interpreter.getInstance().module[module]?.variable?.forEach((entry) {
      if (entry.name == fun_name) {
        fun_name = entry.value.value;
        if (entry.value.module != null) {
          module = entry.value.module;
        }
      }
    });
  } else {
    localEnvironment?.forEach((entry) {
      if (entry.name == fun_name) {
        fun_name = entry.value.value;
        if (entry.value.module != null) {
          module = entry.value.module;
        }
      }
    });
  }

  FunctionDefinition functionDefinition = search_function(module, fun_name);
  if (functionDefinition == null) {
    result.type = StatementResultType.ERROR_RUNTIME_RESULT;
    result.error = "${expression_s.identifier}函数未找到";
    return result;
  }
  if (functionDefinition.isNative) {
    List<Value> args = List();

    for (var t1 = expression_s.function_call_expression.argument?.first;
        t1 != null;
        t1 = t1.next) {
      result = expression_statement(localEnvironment, module, t1.expression);
      if (result.type == StatementResultType.ERROR_RUNTIME_RESULT)
        return result;
      args.add(result.return_value);
    }
    result.return_value = functionDefinition.proc(args);
  } else {
    LinkedList<Variable> _localEnvironment = LinkedList(); //申请本地变量
    if (expression_s.function_call_expression.argument.length !=
        functionDefinition.parameter.length) {
      result.type = StatementResultType.ERROR_RUNTIME_RESULT;
      result.error =
          "${expression_s.function_call_expression.function.identifier}参数不匹配";
      return result;
    } else if ((expression_s.function_call_expression.argument.isEmpty) ||
        (functionDefinition.parameter.isEmpty)) {
    } else {
      var arg_p = expression_s.function_call_expression.argument.first;
      var param_p = functionDefinition.parameter.first;
      for (; arg_p != null; param_p = param_p.next, arg_p = arg_p.next) {
        result =
            expression_statement(localEnvironment, module, arg_p.expression);
        if (result.type == StatementResultType.NORMAL_STATEMENT_RESULT) {
          _localEnvironment
              .add(Variable(param_p.name, result.return_value, false));
        } else {
          return result;
        }
      }
    }

    for (var t1 = functionDefinition.block.statement_list.first;
        t1 != null;
        t1 = t1.next) {
      if (t1.type == StatementType.CONTINUE_STATEMENT ||
          t1.type == StatementType.BREAK_STATEMENT) {
        t1.unlink();
      }
    }

    result = interpreter_run(
        _localEnvironment, module, functionDefinition.block.statement_list);

    _localEnvironment = null;
    if (result.type != StatementResultType.ERROR_RUNTIME_RESULT) {
      result.type = StatementResultType.NORMAL_STATEMENT_RESULT;
    }
  }
  return result;
}

StatementResult eval_binary_expression(LinkedList<Variable> localEnvironment,
    String module, Expression expression) {
  StatementResult result1 = StatementResult();
  result1 = expression_statement(
      localEnvironment, module, expression.binary_expression.left);
  if (result1.type == StatementResultType.ERROR_RUNTIME_RESULT) return result1;
  Value left_val = result1.return_value;
  result1 = expression_statement(
      localEnvironment, module, expression.binary_expression.right);
  if (result1.type == StatementResultType.ERROR_RUNTIME_RESULT) return result1;
  Value right_val = result1.return_value;
  StatementResult result = StatementResult();

  ///1.判断是否为== !=
  if (expression.type == ExpressionType.EQ_EXPRESSION) {
    result.return_value.value = (left_val.value == right_val.value);
    result.return_value.type = ValueType.BOOLEAN_VALUE;
    return result;
  } else if (expression.type == ExpressionType.NE_EXPRESSION) {
    result.return_value.value = (left_val.value != right_val.value);
    result.return_value.type = ValueType.BOOLEAN_VALUE;
    return result;
  }

  ///2.判断是否为比较表达式

  ///根据左边类型进行判断
  return binary_expression(left_val, right_val, expression.type);
}

StatementResult binary_expression(
    Value left_val, Value right_val, ExpressionType expression) {
  StatementResult result = StatementResult();
  switch (left_val.type) {
    case ValueType.INT_VALUE:
    case ValueType.DOUBLE_VALUE:
      switch (expression) {
        case ExpressionType.ADD_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(right_val.value.a, right_val.value.b);
            t1.a += left_val.value;
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if (entry.type == ValueType.INT_VALUE) {
                  t3 = left_val.value + entry.value;
                  type = left_val.type;
                } else if (entry.type == ValueType.DOUBLE_VALUE) {
                  t3 = left_val.value + entry.value;
                  type = entry.type;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(left_val.value + entry.value.a, entry.value.b);
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = (left_val.value + right_val.value);
            result.return_value.type =
                (left_val.type == ValueType.DOUBLE_VALUE) ||
                        (right_val.type == ValueType.DOUBLE_VALUE)
                    ? ValueType.DOUBLE_VALUE
                    : ValueType.INT_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.SUB_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(right_val.value.a, right_val.value.b);
            t1.a = left_val.value - t1.a;
            t1.b = -t1.b;
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if (entry.type == ValueType.INT_VALUE) {
                  t3 = left_val.value - entry.value;
                  type = left_val.type;
                } else if (entry.type == ValueType.DOUBLE_VALUE) {
                  t3 = NumUtil.subtract(left_val.value, entry.value);
                  type = entry.type;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(left_val.value - entry.value.a, -entry.value.b);
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = (left_val.value - right_val.value);
            result.return_value.type =
                (left_val.type == ValueType.DOUBLE_VALUE) ||
                        (right_val.type == ValueType.DOUBLE_VALUE)
                    ? ValueType.DOUBLE_VALUE
                    : ValueType.INT_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.MUL_EXPRESSION:
          if ((left_val.value == 0) || (right_val.value == 0)) {
            result.return_value.value = 0;
            result.return_value.type = ValueType.INT_VALUE;
            return result;
          }
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(right_val.value.a, right_val.value.b);
            t1.a = NumUtil.multiply(left_val.value, t1.a);
            t1.b = NumUtil.multiply(left_val.value, t1.b);
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if (entry.type == ValueType.INT_VALUE) {
                  t3 = NumUtil.multiply(left_val.value, entry.value);
                  type = left_val.type;
                } else if (entry.type == ValueType.DOUBLE_VALUE) {
                  t3 = NumUtil.multiply(left_val.value, entry.value);
                  type = entry.type;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(NumUtil.multiply(left_val.value, entry.value.a),
                      NumUtil.multiply(left_val.value, entry.value.b));
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value =
                NumUtil.multiply(left_val.value, right_val.value);
            result.return_value.type =
                (left_val.type == ValueType.DOUBLE_VALUE) ||
                        (right_val.type == ValueType.DOUBLE_VALUE)
                    ? ValueType.DOUBLE_VALUE
                    : ValueType.INT_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.DIV_EXPRESSION:
          if (left_val.value == 0) {
            result.return_value.value = 0;
            result.return_value.type = ValueType.INT_VALUE;
            return result;
          }
          if (right_val.value == 0) {
            result.error = "除数不能为0";
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            return result;
          }
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = right_val.value.a * right_val.value.a +
                right_val.value.b * right_val.value.b;
            var t2 = right_val.value.a * left_val.value / t1;
            var t3 = -right_val.value.b * left_val.value / t1;
            result.return_value.value = Complex(t2, t3);
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ///[todo]带矩阵的除法
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if (entry.type == ValueType.INT_VALUE) {
                  t3 = left_val.value / entry.value;
                  type = left_val.type;
                } else if (entry.type == ValueType.DOUBLE_VALUE) {
                  t3 = left_val.value / entry.value;
                  type = entry.type;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  var t1 = entry.value.a * entry.value.a +
                      entry.value.b * entry.value.b;
                  t3 = Complex(entry.value.a * left_val.value / t1,
                      -entry.value.b * left_val.value / t1);
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = (left_val.value / right_val.value);
            result.return_value.type =
                (left_val.type == ValueType.DOUBLE_VALUE) ||
                        (right_val.type == ValueType.DOUBLE_VALUE)
                    ? ValueType.DOUBLE_VALUE
                    : ValueType.INT_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.MOD_EXPRESSION:
          if (left_val.value == 0) {
            result.return_value.value = 0;
            result.return_value.type = ValueType.INT_VALUE;
            return result;
          }
          if (right_val.value == 0) {
            result.error = "除数不能为0";
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            return result;
          }
          if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if (entry.type == ValueType.INT_VALUE) {
                  t3 = left_val.value % entry.value;
                  type = left_val.type;
                } else if (entry.type == ValueType.DOUBLE_VALUE) {
                  t3 = left_val.value % entry.value;
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = (left_val.value % right_val.value);
            result.return_value.type =
                (left_val.type == ValueType.DOUBLE_VALUE) ||
                        (right_val.type == ValueType.DOUBLE_VALUE)
                    ? ValueType.DOUBLE_VALUE
                    : ValueType.INT_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.BIT_AND_EXPRESSION:
          if (left_val.type == ValueType.INT_VALUE) {
            if (right_val.type == ValueType.INT_VALUE) {
              result.return_value.value = (left_val.value & right_val.value);
              result.return_value.type = ValueType.INT_VALUE;
            } else if (right_val.type == ValueType.ARRAY_VALUE) {
              ArrayValue t1 = right_val.value;
              ArrayValue t2 = ArrayValue();
              t1.array.forEach((element) {
                LinkedList<Value> value = LinkedList();
                element.forEach((entry) {
                  var type;
                  var t3;
                  if (entry.type == ValueType.INT_VALUE) {
                    t3 = left_val.value & entry.value;
                    type = left_val.type;
                  } else if (entry.type == ValueType.ARRAY_VALUE) {
                    if (entry.value is ArrayValue) {
                      ArrayValue t4 = ArrayValue();
                      entry.value.array.forEach((e) {
                        LinkedList<Value> t5 = LinkedList();
                        e.forEach((f) {
                          if ((f.type == ValueType.INT_VALUE) ||
                              (f.type == ValueType.ARRAY_VALUE))
                            t5.add(binary_expression(left_val, f, expression)
                                .return_value);
                          else
                            t5.add(Value(f.type, f.value));
                        });
                        t4.array.add(t5);
                      });
                      t4.length = entry.value.length;
                      t4.hang = entry.value.hang;
                      t4.lie = entry.value.lie;
                      t3 = t4;
                      type = entry.type;
                    }
                  } else {
                    t3 = entry.value;
                    type = entry.type;
                  }
                  value.add(Value(type, t3));
                });
                t2.array.add(value);
              });
              t2.length = t1.length;
              t2.lie = t1.lie;
              t2.hang = t1.hang;
              result.return_value.value = t2;
              result.return_value.type = ValueType.ARRAY_VALUE;
            } else {
              result.type = StatementResultType.ERROR_RUNTIME_RESULT;
              result.error = "表达式错误";
            }
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "非整数型";
          }
          break;
        case ExpressionType.BIT_OR_EXPRESSION:
          if (left_val.type == ValueType.INT_VALUE) {
            if (right_val.type == ValueType.INT_VALUE) {
              result.return_value.value = (left_val.value | right_val.value);
              result.return_value.type = ValueType.INT_VALUE;
            } else if (right_val.type == ValueType.ARRAY_VALUE) {
              ArrayValue t1 = right_val.value;
              ArrayValue t2 = ArrayValue();
              t1.array.forEach((element) {
                LinkedList<Value> value = LinkedList();
                element.forEach((entry) {
                  var type;
                  var t3;
                  if (entry.type == ValueType.INT_VALUE) {
                    t3 = left_val.value | entry.value;
                    type = left_val.type;
                  } else if (entry.type == ValueType.ARRAY_VALUE) {
                    if (entry.value is ArrayValue) {
                      ArrayValue t4 = ArrayValue();
                      entry.value.array.forEach((e) {
                        LinkedList<Value> t5 = LinkedList();
                        e.forEach((f) {
                          if ((f.type == ValueType.INT_VALUE) ||
                              (f.type == ValueType.ARRAY_VALUE))
                            t5.add(binary_expression(left_val, f, expression)
                                .return_value);
                          else
                            t5.add(Value(f.type, f.value));
                        });
                        t4.array.add(t5);
                      });
                      t4.length = entry.value.length;
                      t4.hang = entry.value.hang;
                      t4.lie = entry.value.lie;
                      t3 = t4;
                      type = entry.type;
                    }
                  } else {
                    t3 = entry.value;
                    type = entry.type;
                  }
                  value.add(Value(type, t3));
                });
                t2.array.add(value);
              });
              t2.length = t1.length;
              t2.lie = t1.lie;
              t2.hang = t1.hang;
              result.return_value.value = t2;
              result.return_value.type = ValueType.ARRAY_VALUE;
            } else {
              result.type = StatementResultType.ERROR_RUNTIME_RESULT;
              result.error = "表达式错误";
            }
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "非整数型";
          }
          break;
        case ExpressionType.BIT_XOR_EXPRESSION:
          if (left_val.type == ValueType.INT_VALUE) {
            if (right_val.type == ValueType.INT_VALUE) {
              result.return_value.value = (left_val.value ^ right_val.value);
              result.return_value.type = ValueType.INT_VALUE;
            } else if (right_val.type == ValueType.ARRAY_VALUE) {
              ArrayValue t1 = right_val.value;
              ArrayValue t2 = ArrayValue();
              t1.array.forEach((element) {
                LinkedList<Value> value = LinkedList();
                element.forEach((entry) {
                  var type;
                  var t3;
                  if (entry.type == ValueType.INT_VALUE) {
                    t3 = left_val.value | entry.value;
                    type = left_val.type;
                  } else if (entry.type == ValueType.ARRAY_VALUE) {
                    if (entry.value is ArrayValue) {
                      ArrayValue t4 = ArrayValue();
                      entry.value.array.forEach((e) {
                        LinkedList<Value> t5 = LinkedList();
                        e.forEach((f) {
                          if ((f.type == ValueType.INT_VALUE) ||
                              (f.type == ValueType.ARRAY_VALUE))
                            t5.add(binary_expression(left_val, f, expression)
                                .return_value);
                          else
                            t5.add(Value(f.type, f.value));
                        });
                        t4.array.add(t5);
                      });
                      t4.length = entry.value.length;
                      t4.hang = entry.value.hang;
                      t4.lie = entry.value.lie;
                      t3 = t4;
                      type = entry.type;
                    }
                  } else {
                    t3 = entry.value;
                    type = entry.type;
                  }
                  value.add(Value(type, t3));
                });
                t2.array.add(value);
              });
              t2.length = t1.length;
              t2.lie = t1.lie;
              t2.hang = t1.hang;
              result.return_value.value = t2;
              result.return_value.type = ValueType.ARRAY_VALUE;
            } else {
              result.type = StatementResultType.ERROR_RUNTIME_RESULT;
              result.error = "表达式错误";
            }
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "非整数型";
          }
          break;
        case ExpressionType.GT_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value =
                NumUtil.multiply(left_val.value, left_val.value) > t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = left_val.value > right_val.value;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.GE_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value =
                NumUtil.multiply(left_val.value, left_val.value) >= t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = left_val.value >= right_val.value;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.LT_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value =
                NumUtil.multiply(left_val.value, left_val.value) < t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = left_val.value < right_val.value;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.LE_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value =
                NumUtil.multiply(left_val.value, left_val.value) <= t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = left_val.value <= right_val.value;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        default:
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "运算符错误";
          break;
      }
      break;
    case ValueType.STRING_VALUE:
      if (expression == ExpressionType.ADD_EXPRESSION) {
        result.return_value.value = left_val.value + right_val.value.toString();
        result.return_value.type = ValueType.STRING_VALUE;
      } else {
        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
        result.error = "字符串只能使用加法";
      }
      break;
    case ValueType.REGEXP_VALUE:
      if ((expression == ExpressionType.ADD_EXPRESSION) &&
          (expression == ExpressionType.REGEXP_EXPRESSION)) {
        result.return_value.value = left_val.value + right_val.value.toString();
        result.return_value.type = ValueType.REGEXP_VALUE;
      } else {
        result.type = StatementResultType.ERROR_RUNTIME_RESULT;
        result.error = "正则只能加正则";
      }
      break;
    case ValueType.COMPLEX_VALUE:
      switch (expression) {
        case ExpressionType.ADD_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(right_val.value.a, right_val.value.b);
            t1.a += left_val.value.a;
            t1.b += left_val.value.b;
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if ((entry.type == ValueType.INT_VALUE) ||
                    (entry.type == ValueType.DOUBLE_VALUE)) {
                  t3 =
                      Complex(left_val.value.a + entry.value, left_val.value.b);
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(left_val.value.a + entry.value.a,
                      left_val.value.b + entry.value.b);
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value =
                Complex(left_val.value.a + right_val.value, left_val.value.b);
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.SUB_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(right_val.value.a, right_val.value.b);
            t1.a = NumUtil.subtract(left_val.value.a, t1.a);
            t1.b = NumUtil.subtract(left_val.value.b, t1.b);
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if ((entry.type == ValueType.INT_VALUE) ||
                    (entry.type == ValueType.DOUBLE_VALUE)) {
                  t3 = Complex(NumUtil.subtract(left_val.value.a, entry.value),
                      left_val.value.b);
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(
                      NumUtil.subtract(left_val.value.a, entry.value.a),
                      NumUtil.subtract(left_val.value.b, entry.value.b));
                  type = entry.type;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = Complex(
                NumUtil.subtract(left_val.value.a, right_val.value),
                left_val.value.b);
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.MUL_EXPRESSION:
          if ((left_val.value == 0) || (right_val.value == 0)) {
            result.return_value.value = 0;
            result.return_value.type = ValueType.INT_VALUE;
            return result;
          }
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            Complex t1 = Complex(
                NumUtil.multiply(left_val.value.a, right_val.value.a) -
                    NumUtil.multiply(left_val.value.b, right_val.value.b),
                NumUtil.multiply(left_val.value.a, right_val.value.b) +
                    NumUtil.multiply(left_val.value.b, right_val.value.a));
            result.return_value.value = t1;
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if ((entry.type == ValueType.INT_VALUE) ||
                    (entry.type == ValueType.DOUBLE_VALUE)) {
                  t3 = Complex(NumUtil.multiply(left_val.value.a, entry.value),
                      NumUtil.multiply(left_val.value.b, entry.value));
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  t3 = Complex(
                      NumUtil.subtract(
                          NumUtil.multiply(left_val.value.a, entry.value.a),
                          NumUtil.multiply(left_val.value.b, entry.value.b)),
                      NumUtil.add(
                          NumUtil.multiply(left_val.value.a, entry.value.b),
                          NumUtil.multiply(left_val.value.b, entry.value.a)));
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = Complex(
                NumUtil.multiply(left_val.value.a, right_val.value),
                NumUtil.multiply(left_val.value.b, right_val.value));
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.DIV_EXPRESSION:
          if (left_val.value == 0) {
            result.return_value.value = 0;
            result.return_value.type = ValueType.INT_VALUE;
            return result;
          }
          if (right_val.value == 0) {
            result.error = "除数不能为0";
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            return result;
          }
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = right_val.value.a * right_val.value.a +
                right_val.value.b * right_val.value.b;
            var t2 = (right_val.value.a * left_val.value.a +
                    right_val.value.b * left_val.value.b) /
                t1;
            var t3 = (right_val.value.a * left_val.value.b -
                    right_val.value.b * left_val.value.a) /
                t1;
            result.return_value.value = Complex(t2, t3);
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else if (right_val.type == ValueType.ARRAY_VALUE) {
            ///[todo]带矩阵的除法
            ArrayValue t1 = right_val.value;
            ArrayValue t2 = ArrayValue();
            t1.array.forEach((element) {
              LinkedList<Value> value = LinkedList();
              element.forEach((entry) {
                var type;
                var t3;
                if ((entry.type == ValueType.INT_VALUE) ||
                    (entry.type == ValueType.DOUBLE_VALUE)) {
                  t3 = Complex(left_val.value.a / entry.value,
                      left_val.value.b / entry.value);
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.COMPLEX_VALUE) {
                  var t1 = entry.value.a * entry.value.a +
                      entry.value.b * entry.value.b;
                  var t2 = (entry.value.a * left_val.value.a +
                          entry.value.b * left_val.value.b) /
                      t1;
                  var t4 = (entry.value.a * left_val.value.b -
                          entry.value.b * left_val.value.a) /
                      t1;
                  t3 = Complex(t2, t4);
                  type = ValueType.COMPLEX_VALUE;
                } else if (entry.type == ValueType.ARRAY_VALUE) {
                  if (entry.value is ArrayValue) {
                    ArrayValue t4 = ArrayValue();
                    entry.value.array.forEach((e) {
                      LinkedList<Value> t5 = LinkedList();
                      e.forEach((f) {
                        if ((f.type == ValueType.INT_VALUE) ||
                            (f.type == ValueType.DOUBLE_VALUE) ||
                            (f.type == ValueType.ARRAY_VALUE) ||
                            (f.type == ValueType.COMPLEX_VALUE))
                          t5.add(binary_expression(left_val, f, expression)
                              .return_value);
                        else
                          t5.add(Value(f.type, f.value));
                      });
                      t4.array.add(t5);
                    });
                    t4.length = entry.value.length;
                    t4.hang = entry.value.hang;
                    t4.lie = entry.value.lie;
                    t3 = t4;
                    type = entry.type;
                  }
                } else {
                  t3 = entry.value;
                  type = entry.type;
                }
                value.add(Value(type, t3));
              });
              t2.array.add(value);
            });
            t2.length = t1.length;
            t2.lie = t1.lie;
            t2.hang = t1.hang;
            result.return_value.value = t2;
            result.return_value.type = ValueType.ARRAY_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            result.return_value.value = Complex(
                left_val.value.a / right_val.value,
                left_val.value.b / right_val.value);
            result.return_value.type = ValueType.COMPLEX_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.GT_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value = t1 > t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            result.return_value.value =
                t1 > NumUtil.multiply(right_val.value, right_val.value);
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.GE_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value = t1 >= t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            result.return_value.value =
                t1 >= NumUtil.multiply(right_val.value, right_val.value);
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.LT_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value = t1 < t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            result.return_value.value =
                t1 < NumUtil.multiply(right_val.value, right_val.value);
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        case ExpressionType.LE_EXPRESSION:
          if (right_val.type == ValueType.COMPLEX_VALUE) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            var t2 = NumUtil.multiply(right_val.value.a, right_val.value.a) +
                NumUtil.multiply(right_val.value.b, right_val.value.b);
            result.return_value.value = t1 <= t2;
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else if ((right_val.type == ValueType.INT_VALUE) ||
              (right_val.type == ValueType.DOUBLE_VALUE)) {
            var t1 = NumUtil.multiply(left_val.value.a, left_val.value.a) +
                NumUtil.multiply(left_val.value.b, left_val.value.b);
            result.return_value.value =
                t1 <= NumUtil.multiply(right_val.value, right_val.value);
            result.return_value.type = ValueType.BOOLEAN_VALUE;
          } else {
            result.type = StatementResultType.ERROR_RUNTIME_RESULT;
            result.error = "表达式错误";
          }
          break;
        default:
          result.type = StatementResultType.ERROR_RUNTIME_RESULT;
          result.error = "运算符错误";
          break;
      }
      break;
    case ValueType.ARRAY_VALUE:

      ///[todo]
      break;
    case ValueType.BOOLEAN_VALUE:
    case ValueType.NULL_VALUE:
    case ValueType.FUNCTION_VALUE:
      result.type = StatementResultType.ERROR_RUNTIME_RESULT;
      result.error = "运算符错误";
      break;
    case ValueType.NATIVE_POINTER_VALUE:
      break;
  }
  return result;
}
